package com.yangyang.rpc.core.netcom.common;

import com.yangyang.rpc.core.netcom.common.client.AbstractClient;
import com.yangyang.rpc.core.netcom.common.server.AbstractServer;
import com.yangyang.rpc.core.netcom.netty.client.NettyClient;
import com.yangyang.rpc.core.netcom.netty.server.NettyServer;

/**
 * 通信方式列表
 * Created by chenshunyang on 2016/11/21.
 */
public enum  NetComEnum {

    NETTY(NettyServer.class, NettyClient.class,true);

    public final Class<? extends AbstractServer> serverClass;
    public final Class<? extends AbstractClient> clientClass;
    public final boolean autoMatch;

    NetComEnum(Class<? extends AbstractServer> serverClass, Class<? extends AbstractClient> clientClass,boolean autoMatch) {
        this.serverClass = serverClass;
        this.clientClass = clientClass;
        this.autoMatch = autoMatch;
    }

    public static NetComEnum autoMatch(String name, NetComEnum defaultEnum) {
        for (NetComEnum item : NetComEnum.values()) {
            if (item.autoMatch && item.name().equals(name)) {
                return item;
            }
        }
        return defaultEnum;
    }
}
